# coding:utf-8

from django import forms
from django.forms.models import modelformset_factory
from models import IDataPage, IDataTextField, IDataImageField
from gettext import gettext as _

class IPageForm(forms.ModelForm):
    def clean_name(self):
        data = self.cleaned_data['name']
        if len(data) < 4:
            raise forms.ValidationError(_(u"Минимум 4-ри символа."))
        return data

    class Meta:
        model = IDataPage
        exclude = ('owner', )

class IDataTextFieldForm(forms.ModelForm):
    class Meta:
        model = IDataTextField
        exclude = ('page', )
        widgets = {
            'value': forms.Textarea(attrs={'cols': 120, 'rows': 5, 'style':'width:300px'  }),
            }

class IDataImageFieldForm(forms.ModelForm):
    class Meta:
        model = IDataImageField
        exclude = ( 'page', )


IDataTextFieldFormSet = modelformset_factory(IDataTextField, form=IDataTextFieldForm)
IDataImageFieldFormSet = modelformset_factory(IDataImageField, exclude=('page',))
